package com.imc.platform.base.menu.dao.repository;

import com.imc.platform.base.menu.pojo.Menu;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Set;

/**
 * Created by tanweiping on 2018/7/20.
 */
@Repository
public interface MenuRepository extends JpaRepository<Menu, String>, JpaSpecificationExecutor<Menu> {

    @Query(
            nativeQuery = true,
            value = "SELECT distinct  *  FROM \n" +
                    "  t_menu menu \n" +
                    "LEFT JOIN t_role_menu role_menu \n" +
                    "  ON menu.id  = role_menu.menuId \n" +
                    "LEFT JOIN t_role role \n" +
                    "  ON role.id = role_menu.roleId \n" +
                    "LEFT JOIN t_role_user role_user \n" +
                    "    ON role.id = role_user.roleId \n" +
                    "LEFT JOIN t_user tuser \n" +
                    "    ON tuser.id = :userId"

    )
    Set<Menu> findAllByUserId(@Param("userId") String userId);
}
